package com.example.bingobox.dialog;

import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ExpandableListView;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import com.example.bingobox.R;
import com.example.bingobox.adapter.LocationMarkAdapter;
import com.example.bingobox.model.State;

public class LocationManageDialog extends DialogFragment {
    private State state;
    private LocationMarkAdapter adapter;
    private OnLocationUpdateListener listener;

    public static LocationManageDialog newInstance(State state) {
        LocationManageDialog dialog = new LocationManageDialog();
        dialog.state = state;
        return dialog;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
        LayoutInflater inflater = requireActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.dialog_location_manage, null);

        ExpandableListView listView = view.findViewById(R.id.location_list);
        adapter = new LocationMarkAdapter(requireContext(), state);
        listView.setAdapter(adapter);

        // 默认展开所有组
        for (int i = 0; i < adapter.getGroupCount(); i++) {
            listView.expandGroup(i);
        }

        return builder.setView(view)
                .setTitle("查看城市与标记")
                .setPositiveButton("关闭", null)
                .create();
    }

    public interface OnLocationUpdateListener {
        void onLocationUpdated();
    }

    public void setOnLocationUpdateListener(OnLocationUpdateListener listener) {
        this.listener = listener;
    }
} 